import React, { Component } from 'react'
import Taro from '@tarojs/taro'
import { View } from '@tarojs/components'
import PropTypes from 'prop-types';

class NavigationBar extends Component<any,any> {
  // 定义组件的属性类型
  static propTypes = {
    title: PropTypes.string,
    isBack: PropTypes.bool
  }

  // 默认的属性值
  static defaultProps = {
    title: '',
    isBack: true
  }

  // 返回上一页
  handleNavBack = () => {
    Taro.navigateBack()
  }

  render() {
    const { title, isBack } = this.props

    return (
      <View className='nav-container'>
        {isBack && (
          <View className='nav-back' onClick={this.handleNavBack}>
            返回
          </View>
        )}
        <View className='nav-title'>{title}</View>
      </View>
    )
  }
}

export default NavigationBar